package edu.byu.intex2.data.bo;

import edu.byu.intex2.data.DataException;
import edu.byu.intex2.data.dao.*;
import edu.byu.intex2.data.bo.ServiceLine;
import java.util.*;

/*******************************************************************************
 *
 *        @author Brady White
 *          Date: Mar 3, 2009
 *   Description: Service performed on a physical car.
 * Last Revision: Mar 3, 2009
 *
 ******************************************************************************/
public class Service extends BusinessObject {

    private Date date = null;
    /** Pricing */
    private double totalPrice = 0;
    private double tax = 0;
    /** Foreign Keys */
    private String customerId = null;
    private String technicianId = null;
    private String physicalCarId = null;
    private String serviceFacilityId = null;
    /** Foreign Objects */
    private Customer customer = null;
    private Technician technician = null;
    private PhysicalCar physicalcar = null;
    private ServiceFacility servicefacility = null;
    /** ServiceLines */
    private List<ServiceLine> serviceLines = new ArrayList<ServiceLine>();

    /** Creates a new instance of the BO */
    public Service(String id) {
        super(id);
    }

    /** Convenience method to call the correct DAO to save this business object */
    public void save() throws DataException {
        ServiceDAO.getInstance().save(this);
    }

    /**
     * @return the sedate
     */
    public Date getDate() {
        return date;
    }

    /**
     * @param sedate the sedate to set
     */
    public void setDate(Date date) {
        this.date = date;
        this.setDirty(true);
    }

    /**
     * @return the totalprice
     */
    public double getTotalPrice() {
        return totalPrice;
    }

    /**
     * @param totalprice the totalprice to set
     */
    public void setTotalPrice(double totalprice) {
        this.totalPrice = totalprice;
        this.setDirty(true);
    }

    /**
     * @return the tax
     */
    public double getTax() {
        return tax;
    }

    /**
     * @param tax the tax to set
     */
    public void setTax(double tax) {
        this.tax = tax;
        this.setDirty(true);
    }

    /**
     * @return the customerId
     */
    public String getCustomerId() {
        return customerId;
    }

    /**
     * @param customerId the customerId to set
     */
    public void setCustomerId(String customerId) {
        this.customerId = customerId;
        this.setDirty(true);
    }

    /**
     * @return the technicianid
     */
    public String getTechnicianId() {
        return technicianId;
    }

    /**
     * @param technicianid the technicianid to set
     */
    public void setTechnicianId(String technicianId) {
        this.technicianId = technicianId;
        this.setDirty(true);
    }

    /**
     * @return the physicalcarId
     */
    public String getPhysicalCarId() {
        return physicalCarId;
    }

    /**
     * @param physicalcarId the physicalcarId to set
     */
    public void setPhysicalCarId(String physicalcarId) {
        this.physicalCarId = physicalcarId;
        this.setDirty(true);
    }

    /**
     * @return the servicefacilityid
     */
    public String getServiceFacilityId() {
        return serviceFacilityId;
    }

    /**
     * @param dealershipid the dealershipid to set
     */
    public void setServiceFacilityId(String servicefacilityid) {
        this.serviceFacilityId = servicefacilityid;
        this.setDirty(true);
    }

    /**
     * @return the customer
     */
    public Customer getCustomer() throws DataException {
        if (customer == null) {
            try {
                customer = CustomerDAO.getInstance().read(this.id);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return customer;
    }

    /**
     * @param customer the customer to set
     */
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    /**
     * @return the technician
     */
    public Technician getTechnician() throws DataException {
        if (technician == null) {
            try {
                technician = TechnicianDAO.getInstance().read(this.id);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return technician;
    }

    /**
     * @param technician the technician to set
     */
    public void setTechnician(Technician technician) {
        this.technician = technician;
    }

    /**
     * @return the physicalcar
     */
    public PhysicalCar getPhysicalCar() throws DataException {
        if (physicalcar == null) {
            try {
                physicalcar = PhysicalCarDAO.getInstance().read(this.id);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return physicalcar;
    }

    /**
     * @param physicalcar the physicalcar to set
     */
    public void setPhysicalCar(PhysicalCar physicalcar) {
        this.physicalcar = physicalcar;
        this.physicalCarId = physicalcar.getId();
        this.setDirty(true);
    }

    /**
     * @return the servicefacility
     */
    public ServiceFacility getServiceFacility() throws DataException {
        if (servicefacility == null) {
            try {
                servicefacility = ServiceFacilityDAO.getInstance().read(this.id);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return servicefacility;
    }

    /**
     * @param servicefacility the servicefacility to set
     */
    public void setServiceFacility(ServiceFacility servicefacility) {
        this.servicefacility = servicefacility;
    }

    /**
     * @return the serviceLines
     */
    public List<ServiceLine> getServiceLines() {
        return serviceLines;
    }

    /**
     * @param serviceLines the serviceLines to set
     */
    public void setServiceLines(ArrayList serviceLines) {
        this.serviceLines = serviceLines;
    }

    /**
     * @param serviceLine to add
     */
    public void addServiceLine(ServiceLine sl){
        getServiceLines().add(sl);
    }
}//class